package com.javabasic.algorithm.leetcode;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/6/12 11:24
 */
public class 计算应缴税款总额 {

    public double calculateTax(int[][] brackets, int income) {
        int bracketLen = brackets.length;
        double result = 0;
        int preBracket = 0;
        for (int i = 0; i < bracketLen; i++) {
            System.out.println("preBracket = " + preBracket + " brackets[i][0] = " + brackets[i][0] + " brackets[i][1] = " + brackets[i][1] + " income = " + income);
            if (income >= brackets[i][0]) {
                result = result +  ((brackets[i][0]-preBracket) * brackets[i][1] * 1.0 / 100);
            } else {
                result = result + ((income-preBracket) * brackets[i][1] * 1.0 / 100);
                break;
            }
            System.out.println("result = " + result);
            preBracket = brackets[i][0];
        }
        return result;
    }
}
